/*
 * @Author: szx
 * @Date: 2021-12-23 14:06:20
 * @LastEditTime: 2021-12-23 14:13:51
 * @Description:
 * @FilePath: \leetcode\100-199\113\113.js
 */
/**
 * @param {TreeNode} root
 * @param {number} targetSum
 * @return {number[][]}
 */
var pathSum = function (root, targetSum) {
    const res = [];
    const dfs = (root, target, path) => {
        if (!root) return;
        path.push(root.val);
        if (!root.left && !root.right && target == root.val) {
            res.push(path.slice());
        }
        dfs(root.left, target - root.val, path);
        dfs(root.right, target - root.val, path);
        path.pop();
    };
    dfs(root, targetSum, []);
    return res;
};
